import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    list: [],
  },
  getters: {
    num(state) {
      let num1 = state.list.filter((i) => i.status == 0).length;
      let num2 = state.list.filter((i) => i.status == 1).length;
      let num3 = state.list.filter((i) => i.status == 2).length;
      return { num1, num2, num3 };
    },
    //getters的第一参数永远都是state
    // 调用的时候this.$store.getters.xxx
  },
  //getters跟计算属性一样
  mutations: {
    setData(state, val) {
      state.list = val;
    },
    //把数据存进vuex
    change(state, obj) {
      state.list.forEach((i) => {
        if (i.status == obj.a) {
          i.status = obj.b;
        }
      });
    },
  },
  actions: {},
  modules: {},
});
